from pyecharts.charts import Bar3D
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
import random
#001===============================================
# bar3d
bar3d = Bar3D(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1200px',
    height='720px'))
data = [(i,j,random.randint(0,12)) for i in range(20) for j in range(6)]
bar3d.add(
    '3D柱形图',
    data,
    xaxis3d_opts=opts.Axis3DOpts(Faker.clock,type_='category'),
    yaxis3d_opts=opts.Axis3DOpts(Faker.week_en,type_='category'),
    zaxis3d_opts=opts.Axis3DOpts(type_='value')
)
bar3d.set_global_opts(
    visualmap_opts=opts.VisualMapOpts(max_=20),
    title_opts=opts.TitleOpts(title='Bar3D-柱形图')
)
#002===============================================
# pie
from pyecharts.faker import Faker
from pyecharts.charts import Pie
import pyecharts.options as opts

pie = Pie()

#pie.add('饼图',[list(z) for z in zip(Faker.choose(),Faker.values())])
#pie.set_global_opts(title_opts=opts.TitleOpts(title='Pie-饼图'))
#pie.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}'))

pie.add(
    '饼图',
    [list(z) for z in zip(Faker.choose(),Faker.values())],
    radius=['40%','75%'], # radius 表示内环和外环半径，列表类型
    # rosetype设置玫瑰饼图模式, area所有扇区圆心角相同，仅通过半径展现数据大小
    rosetype='area'
)

pie.set_global_opts(title_opts=opts.TitleOpts(title='饼图'))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}'))

#003===============================================
# effect_scatter
from pyecharts.faker import Faker
from pyecharts.charts import EffectScatter
import pyecharts.options as opts
from pyecharts.globals import SymbolType

effect_scatter = EffectScatter()
effect_scatter.add_xaxis(Faker.choose())
effect_scatter.add_yaxis(
    '散点图',
    Faker.values(),
    symbol=SymbolType.DIAMOND
)
effect_scatter.set_global_opts(title_opts=opts.TitleOpts(title='动态散点图'))

#004===============================================
# bar
from pyecharts.charts import Bar
bar = Bar()
x = ['葡萄','橘子','香蕉','榴莲','苹果','梨']
y = [123,32,56,99,210,100]
bar.add_xaxis(x)
bar.add_yaxis('水果',y)

#005===============================================
# funnel
from pyecharts.faker import Faker
from pyecharts.charts import Funnel
import pyecharts.options as opts
from pyecharts.globals import SymbolType

funnel = Funnel()
funnel.add(
    '用户转化率',
    [list(z) for z in zip(Faker.choose(),Faker.values())],
    label_opts=opts.LabelOpts(position='inside')
)
funnel.set_global_opts(title_opts=opts.TitleOpts(title="漏斗图"))


#006===============================================
# line
from pyecharts.faker import Faker
from pyecharts.charts import Line
import pyecharts.options as opts

line = Line()
line.add_xaxis(Faker.choose())
# is_smooth 是否让折线变平滑
line.add_yaxis('商家A',Faker.values(),is_smooth=True)
line.add_yaxis('商家B',Faker.values())
line.set_global_opts(title_opts=opts.TitleOpts(title='折线图'))

#007===============================================
# geo
from pyecharts.faker import Faker
from pyecharts.charts import Geo
import pyecharts.options as opts
from pyecharts.globals import ThemeType

geo = Geo(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1600px',
    height='800px'))
geo.add_schema(maptype='china')
geo.add('geo',
        [list(z) for z in zip(Faker.provinces,Faker.values())],
        type_='heatmap'
        )
geo.set_global_opts(
    visualmap_opts=opts.VisualMapOpts(),
    title_opts=opts.TitleOpts(title='Geo-地图')
)
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

#008===============================================
# line008
from pyecharts.faker import Faker
from pyecharts.charts import Line
import pyecharts.options as opts

line008 = Line()
line008.add_xaxis(Faker.choose())
# is_smooth 是否让折线变平滑
line008.add_yaxis('商家A',
               Faker.values(),
               is_smooth=True,
               areastyle_opts=opts.AreaStyleOpts(
                   opacity=0.2,
                   color={
                       'type':'linear',
                       'x':0,
                       'y':0,
                       'x2':0,
                       'y2':1,
                       'colorStops':[{
                           'offset':0,'color':'red'},
                           {'offset':1,'color':'blue'
                       }]
                   }
               )
               )
line008.add_yaxis('商家B',Faker.values())
line008.set_global_opts(title_opts=opts.TitleOpts(title='折线图'))


#009===============================================
# bar009
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
bar009 = Bar(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1920px',
    height='1080px'))
x = ['葡萄','橘子','香蕉','榴莲','苹果','梨']
y = [123,32,56,99,210,100]
bar009.add_xaxis(x)
bar009.add_yaxis('水果',y)
bar009.set_global_opts(title_opts=opts.TitleOpts(title='水果数量',subtitle='副标题'))


#010===============================================
# liquid
from pyecharts.charts import Liquid
import pyecharts.options as opts

liquid = Liquid()
# is_outline_show 是否显示外边框
# is_animation 是否显示动画效果
# shape 边框形状，和symbol可用的形状类似，还可以自定义
liquid.add('水球图',[0.7,0.6,0.5])
liquid.set_global_opts(title_opts=opts.TitleOpts(title='Liquid-水球图'))

#011===============================================
# radar
from pyecharts.charts import Radar
import pyecharts.options as opts
from pyecharts.globals import ThemeType
radar = Radar(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1700px',
    height='800px'))
v1 = [
    [4300,31560,28000,25626,19000,15000],
    [3300,30000,26000,25000,17000,16000]
]
v2 = [[5000,14000,25000,19000,35000,18000]]
radar.add_schema(
    schema=[
        opts.RadarIndicatorItem(name='销售',max_=6500),
        opts.RadarIndicatorItem(name='管理',max_=16000),
        opts.RadarIndicatorItem(name='信息技术',max_=9900),
        opts.RadarIndicatorItem(name='客服',max_=6900),
        opts.RadarIndicatorItem(name='研发',max_=18000),
        opts.RadarIndicatorItem(name='市场',max_=12600)
    ]
)
radar.add('预算分配',v1)
radar.add('实际开销',v2)
radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
radar.set_global_opts(title_opts=opts.TitleOpts(title='Radar-雷达图'))
#012===============================================
# bar012
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
bar012 = Bar(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1000px',
    height='720px'))
x = ['葡萄','橘子','香蕉','榴莲','苹果','梨']
y = [123,32,56,99,210,100]
bar012.add_xaxis(x)
bar012.add_yaxis('水果',y)
bar012.set_global_opts(title_opts=opts.TitleOpts(
    title='水果数量',
    subtitle='副标题'),
    xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=30)))# -90°到90°


#013===============================================
# bar013
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
# 设置图表大小
bar013 = Bar(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1000px',
    height='720px'))
x = ['葡萄','橘子','香蕉','榴莲','苹果','梨']
y1 = [123,32,56,99,210,100]
y2 = [100,132,46,69,90,120]
bar013.add_xaxis(x)
bar013.add_yaxis('水果1',y1)
bar013.add_yaxis('水果2',y2)
# 将数据堆叠在一起，可以将两两数据进行堆叠,用stack方法
#bar.add_yaxis('水果1',y1,stack='stack1')
#bar.add_yaxis('水果2',y2,stack='stack1')

bar013.set_global_opts(title_opts=opts.TitleOpts(
    title='水果数量',
    subtitle='副标题'))

#014===============================================
# wordcloud
from pyecharts.charts import WordCloud
import pyecharts.options as opts

words = [
    ('Sam S Club',10000),
    ('Macys',6000),
    ('Amy Schumer',4300),
    ('Beautifully',5000),
    ('Congratulations',6500),
    ('Jurassic',4500),
    ('Love',5500),
    ('Honorable',3900),
    ('King',4800),
]
wordcloud = WordCloud()
wordcloud.add('词云图',words,word_size_range=[20,100])
wordcloud.set_global_opts(title_opts=opts.TitleOpts(title='WordCloud-词云图'))


#015===============================================
# bar015
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
# 设置图表大小
bar015 = Bar(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1000px',
    height='720px'))
x = ['葡萄','橘子','香蕉','榴莲','苹果','梨']
y1 = [123,32,56,99,210,100]
y2 = [100,132,46,69,90,120]
bar015.add_xaxis(x)
bar015.add_yaxis('水果1',y1)
bar015.add_yaxis('水果2',y2)
# 设置标题
bar015.set_global_opts(title_opts=opts.TitleOpts(
    title='水果数量',
    subtitle='副标题'))
# 设置标记点和标记线
bar015.set_series_opts(
    label_opts=opts.LabelOpts(is_show=False),
    markpoint_opts=opts.MarkPointOpts(
        data=[
            opts.MarkPointItem(type_='max',name='最大值'),
            opts.MarkPointItem(type_='min',name='最小值')
            ]
        ),
    markline_opts=opts.MarkLineOpts(
        data=[opts.MarkPointItem(type_='average',name='平均值')]
        )
    )
# x轴与y轴互换
#bar.reversal_axis()

#016===============================================
# bar016
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
# 设置图表大小
bar016 = Bar(init_opts=opts.InitOpts(
    theme=ThemeType.PURPLE_PASSION,
    width='1000px',
    height='720px'))
x = ['葡萄','橘子','香蕉','榴莲','苹果','梨']
y1 = [123,32,56,99,210,100]
y2 = [100,132,46,69,90,120]
bar016.add_xaxis(x)
bar016.add_yaxis('水果1',y1)
bar016.add_yaxis('水果2',y2)
# 设置标题
bar016.set_global_opts(
    title_opts=opts.TitleOpts(
        title='水果数量',
        subtitle='副标题'),
    # 设置窗口滑块
    datazoom_opts=[opts.DataZoomOpts()]
    )
# 设置标记点和标记线
bar016.set_series_opts(
    label_opts=opts.LabelOpts(is_show=False),
    markpoint_opts=opts.MarkPointOpts(
        data=[
            opts.MarkPointItem(type_='max',name='最大值'),
            opts.MarkPointItem(type_='min',name='最小值')
            ]
        ),
    markline_opts=opts.MarkLineOpts(
        data=[opts.MarkPointItem(type_='average',name='平均值')]
        )
    )

#017===============================================
# pic
from pyecharts import options as opts
from pyecharts.charts import Sankey

node = [
    {'name': '创建订单-1828'}, {'name': '未支付-935'}, {'name': '已支付-893'},
    {'name': '未发货-114'}, {'name': '已发货-779'}, {'name': '未收货-111'},
    {'name': '已收货-669'}, {'name': '未删除-813'}, {'name': '已删除-122'},
    {'name': '已退款-51'}, {'name': '未退款-65'}, {'name': '待收货-109'}, {'name': '订单完成-601'},
]  # 此处罗列各分支名称，后面的数字代表具体的量值(注：因为pyecharts无法直接显示value，所以需要这样标注)。
link = [
    {'source': '创建订单-1828', 'target': '未支付-935', 'value': 935},
    {'source': '创建订单-1828', 'target': '已支付-893', 'value': 893},
    {'source': '未支付-935', 'target': '未删除-813', 'value': 813},
    {'source': '未支付-935', 'target': '已删除-122', 'value': 122},
    {'source': '已支付-893', 'target': '未发货-114', 'value': 114},
    {'source': '已支付-893', 'target': '已发货-779', 'value': 779},
    {'source': '未发货-114', 'target': '已退款-51', 'value': 49},
    {'source': '未发货-114', 'target': '未退款-65', 'value': 65},
    {'source': '已发货-779', 'target': '未收货-111', 'value': 111},
    {'source': '已发货-779', 'target': '已收货-669', 'value': 668},
    {'source': '未收货-111', 'target': '待收货-109', 'value': 109},
    {'source': '未收货-111', 'target': '已退款-51', 'value': 2},
    {'source': '已收货-669', 'target': '订单完成-601', 'value': 601}, ]

pic = (
    Sankey().add('',
                 node,
                 link,
                 linestyle_opt=opts.LineStyleOpts(opacity=0.3, curve=0.5, color='source'),
                 label_opts=opts.LabelOpts(position='right'),
                 node_gap=30,  # 节点之间的距离,(查看垂直图片的操作orient="vertical")

                 ).set_global_opts(title_opts=opts.TitleOpts(title='电商订单报表一览图'))
)
#018===============================================
# bar_unit
import pyecharts.options as opts
from pyecharts.charts import Bar

label = ['中国科学院数学与系统科学研究院', '浙江大学', '中国科学院物理研究所', '上海交通大学',
         '中国科学院高能物理研究所', '复旦大学', '南京大学', '清华大学', '北京大学', '中国科学技术大学']
mean_kh = [673, 720, 726, 730, 744, 810, 959, 1159, 1307, 1452]
max_kh = [ 198.05, 151.9,400.76,378.82, 526.34, 480.86, 654.15, 688.4, 728.7, 948.45,]

bar_unit=(
    Bar()
    .add_xaxis(label)
    .add_yaxis('课题数量(个)',mean_kh,stack='stack1')
    .add_yaxis('资助金额(万元)',max_kh,stack='stack1')
    #.add_yaxis('最低价位',min_kh)
    .reversal_axis()
    .set_series_opts(label_opts=opts.LabelOpts(position="right"))
    .set_global_opts(title_opts=opts.TitleOpts(title="热门单位/能力展示"))
)

#019===============================================
# pic_topic
import pyecharts.options as opts
from pyecharts.charts import Sankey

topic_201901 = '数学微分方程'
topic_201902 = '交通拓扑规划'
topic_201903 = '组合设计理论'
topic_201904 = '文化传播周期'

topic_201801 = '微分方程 '
topic_201802 = '学校暑期'
topic_201803 = '非线性模型函数'
topic_201804 = '数学方法整数分解'

topic_201701 = '数学非线性模型 '
topic_201702 = '空间几何结构优化'
topic_201703 = '随机代数理论'
topic_201704 = '量子图像算子'

topic_201601 = '量子方法方程 '
topic_201602 = '动力学方法'
topic_201603 = '材料分析'
topic_201604 = '系统效应'

topic_201501 = '纳米材料分子 '
topic_201502 = '结构方法'
topic_201503 = '动力学控制力学'
topic_201504 = '激光辐射'


topic_201401 = '系统耦合分析 '
topic_201402 = '等离子体材料'
topic_201403 = '量子结构动力学方法'
topic_201404 = '纳米分子电子'

topic_201301 = '自旋理论模型 '
topic_201302 = '量子结构方程'
topic_201303 = '电子空间理论'
topic_201304 = '非线性材料'

node = [
    {'name': '2019主题'},
    {'name': topic_201901}, {'name': topic_201902}, {'name': topic_201903}, {'name': topic_201904},

    {'name': '2018主题'},
    {'name': topic_201801}, {'name': topic_201802}, {'name': topic_201803}, {'name': topic_201804},

    {'name': '2017主题'},
    {'name': topic_201701}, {'name': topic_201702}, {'name': topic_201703}, {'name': topic_201704},

    {'name': '2016主题'},
    {'name': topic_201601}, {'name': topic_201602}, {'name': topic_201603}, {'name': topic_201604},

    {'name': '2015主题'},
    {'name': topic_201501}, {'name': topic_201502}, {'name': topic_201503}, {'name': topic_201504},

    {'name': '2014主题'},
    {'name': topic_201401}, {'name': topic_201402}, {'name': topic_201403}, {'name': topic_201404},

    {'name': '2013主题'},
    {'name': topic_201301}, {'name': topic_201302}, {'name': topic_201303}, {'name': topic_201304},

]  # 此处罗列各分支名称，后面的数字代表具体的量值(注：因为pyecharts无法直接显示value，所以需要这样标注)。
link = [
    {'source': '2019主题', 'target': topic_201901, 'value': 1.1},
    {'source': topic_201901, 'target': topic_201902, 'value': 1.1},
    {'source': topic_201902, 'target': topic_201903, 'value': 1.1},
    {'source': topic_201903, 'target': topic_201904, 'value': 1.1},

    {'source': '2018主题', 'target': topic_201801, 'value': 1.2},
    {'source': topic_201801, 'target': topic_201802, 'value': 1.2},
    {'source': topic_201802, 'target': topic_201803, 'value': 1.2},
    {'source': topic_201803, 'target': topic_201804, 'value': 1.2},

    {'source': '2017主题', 'target': topic_201701, 'value': 1.3},
    {'source': topic_201701, 'target': topic_201702, 'value': 1.3},
    {'source': topic_201702, 'target': topic_201703, 'value': 1.3},
    {'source': topic_201703, 'target': topic_201704, 'value': 1.3},

    {'source': '2016主题', 'target': topic_201601, 'value': 1.4},
    {'source': topic_201601, 'target': topic_201602, 'value': 1.4},
    {'source': topic_201602, 'target': topic_201603, 'value': 1.4},
    {'source': topic_201603, 'target': topic_201604, 'value': 1.4},

    {'source': '2015主题', 'target': topic_201501, 'value': 1.5},
    {'source': topic_201501, 'target': topic_201502, 'value': 1.5},
    {'source': topic_201502, 'target': topic_201503, 'value': 1.5},
    {'source': topic_201503, 'target': topic_201504, 'value': 1.5},

    {'source': '2014主题', 'target': topic_201401, 'value': 1.6},
    {'source': topic_201401, 'target': topic_201402, 'value': 1.6},
    {'source': topic_201402, 'target': topic_201403, 'value': 1.6},
    {'source': topic_201403, 'target': topic_201404, 'value': 1.6},

    {'source': '2013主题', 'target': topic_201301, 'value': 1.7},
    {'source': topic_201301, 'target': topic_201302, 'value': 1.7},
    {'source': topic_201302, 'target': topic_201303, 'value': 1.7},
    {'source': topic_201303, 'target': topic_201304, 'value': 1.7},

]

pic_topic = (
    Sankey().add('',
                 node,
                 link,
                 linestyle_opt=opts.LineStyleOpts(opacity=0.3, curve=0.5, color='source'),
                 label_opts=opts.LabelOpts(position='right'),
                 node_gap=30,  # 节点之间的距离,(查看垂直图片的操作orient="vertical")

                 ).set_global_opts(title_opts=opts.TitleOpts(title='各年份主题'))
)

#020===============================================
# bar_req_sup
import pyecharts.options as opts
from pyecharts.charts import Bar


x_index_year = ['2005年', '2006年', '2007年', '2008年', '2009年', '2010年', '2011年', '2012年', '2013年', '2014年', '2015年', '2016年', '2017年', '2018年', '2019年']
support_num = [978, 1095, 851, 926, 1009, 1165, 1431, 1515, 1485, 1375, 1533, 1551, 1673, 1743, 1750]
request_num = [3307, 3812, 3054, 3297, 3702, 4084, 4852, 5635, 4991, 4288, 5001, 5380, 5804, 6544, 6897]


bar_req_sup = Bar()
bar_req_sup.add_xaxis(x_index_year)
bar_req_sup.add_yaxis("申请数（个）", request_num)
bar_req_sup.add_yaxis("资助数（个）", support_num)


bar_req_sup.set_series_opts(
    label_opts=opts.LabelOpts(is_show=True),
    markline_opts=opts.MarkLineOpts(
        data=[opts.MarkPointItem(type_='average',name='平均值')]
        )
    )

bar_req_sup.set_global_opts(title_opts=opts.TitleOpts(title='历年课题申请书与资助数对比分析'),datazoom_opts=[opts.DataZoomOpts()])

# bar_req_sup.render('11_柱状图-坐标可变-描平均线.html')

# ========================
#一个页面显示多个图表：
from pyecharts.charts import Page
page = Page(layout=Page.SimplePageLayout) # 实例化page类
'''
【非常重要】
1.需要显示什么图表，对应在如下page.add()添加就行，如：
page.add(bar_req_sup)
2.图表直接的前后显示顺序，可以自行调整。

'''
page.add(bar3d) # 第一个图显示3D柱状图
page.add(effect_scatter) # 第二个图显示散点图
page.add(bar)# 第三个图显示柱状图
page.add(funnel)
page.add(line)
page.add(geo)
page.add(line008)
page.add(wordcloud)
page.add(liquid)
page.add(pic) # 最后一个图，显示桑基图
page.render("一个页面渲染多张图表.html")
print('运行完成！')


